package com.plugin.manage.controller;

import com.plugin.core.bean.LogAop;
import com.plugin.manage.common.RespObj;
import com.plugin.manage.service.IElderService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * 长者看板控制器
 * 
 * @author mark
 * @date 2025-07-26
 */
@RestController
@RequestMapping("/elder/dashboard")
@Tag(name = "长者看板接口", description = "长者数据统计和看板相关接口")
@Slf4j
public class ElderController {

    @Autowired
    private IElderService elderDashboardService;

    /**
     * 获取自理能力等级百分比统计
     * 查询elder_health_info表的总人数并根据自理等级除以总人数实现等级的百分比
     * 
     * @return 自理能力等级百分比统计结果
     */
    @LogAop(remark = "获取自理能力等级百分比")
    @GetMapping("/selfCareAbility")
    @Operation(summary = "获取自理能力等级百分比", description = "查询elder_health_info表总人数并按自理能力等级计算百分比")
    public RespObj<?> getSelfCareAbilityPercentage() {
        log.info("开始查询自理能力等级百分比统计");
        return elderDashboardService.getSelfCareAbilityPercentage();
    }

    /**
     * 获取护理等级百分比统计
     * 查询elder_health_info表的总人数并根据护理等级除以总人数实现等级的百分比
     * 
     * @return 护理等级百分比统计结果
     */
    @GetMapping("/careLevel")
    @Operation(summary = "获取护理等级百分比", description = "查询elder_health_info表总人数并按护理等级计算百分比")
    public RespObj<?> getCareLevelPercentage() {
        log.info("开始查询护理等级百分比统计");
        return elderDashboardService.getCareLevelPercentage();
    }

    /**
     * 获取床位入驻统计
     * 查询elder_room表的总床位数和已入住床位数，计算入住率百分比
     * 
     * @return 床位入驻统计结果
     */
    @GetMapping("/bedOccupancy")
    @Operation(summary = "获取床位入驻统计", description = "查询总床位数和已入住床位数，计算入住率百分比")
    public RespObj<?> getBedOccupancyStatistics() {
        log.info("开始获取床位入驻统计");
        
        Map<String,Object> result = elderDashboardService.getBedOccupancyStatistics();
        
        log.info("床位入驻统计获取完成");
        
        return new RespObj<Map<String,Object>>().success(result);
    }


    /**
     * 查询活动列表
     * 获取活动名称、开始时间和结束时间
     * 
     * @return 活动列表
     */
    @LogAop
    @GetMapping("/activities")
    @Operation(summary = "查询活动列表", description = "获取所有活动的名称、开始时间和结束时间")
    public RespObj<?> getActivities() {
        log.info("开始查询活动列表");
        RespObj<?> result = elderDashboardService.getActivities();
        log.info("活动列表查询完成");
        return result;
    }

    /**
     * 根据条件查询健康检查异常记录
     * 根据长者姓名、床位号、异常内容、检查时间查询多条记录
     */
    @GetMapping("/healthCheckException")
    @Operation(summary = "查询健康检查异常记录", description = "获取所有健康检查异常记录列表")
    public RespObj<?> getHealthCheckExceptions() {
        log.info("开始查询所有健康检查异常记录");
        
        RespObj<?> result = elderDashboardService.getHealthCheckExceptions();
        log.info("健康检查异常记录查询完成");
        return result;
    }

    @GetMapping("/carePlan")
    @Operation(summary = "查询护理计划记录", description = "获取所有护理计划记录列表")
    public RespObj<?> getCarePlanRecords() {
        log.info("开始查询所有护理计划记录");
        
        RespObj<?> result = elderDashboardService.getCarePlanRecords();
        
        log.info("护理计划记录查询完成");
        
        return result;
    }
}
